home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / WNOUTREF.C < prev    next >
Text File  |  1992-11-21  |  5KB  |  147 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3. #undef wnoutrefresh
  4.  
  5. #ifndef        NDEBUG
  6. char *rcsid_wnoutref = "$Header: c:/curses/portable/RCS/wnoutref.c%v 2.0 1992/11/15 03:29:36 MH Rel $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12. /*man-start*********************************************************************
  13.  
  14.   wnoutrefresh()       - do effiecient refresh
  15.  
  16.   X/Open Description: (part of the wnoutrefresh() description.)
  17.        These two routines allow multiple updates with more efficiency
  18.        than wrefresh() alone.  In addition to all of the window
  19.        structures representing the terminal screen: a physical screen,
  20.        describing what is actually on the screen and a virtual screen,
  21.        describing what the programmer wants to have on  the screen.
  22.  
  23.        The wrefresh() function works by first calling wnoutrefresh(),
  24.        which copies the named window to the virtual screen.  It then
  25.        calls doupdate(), which compares the virtual screen to the
  26.        physical screen and does the actual update.  If the programmer
  27.        wishes to output several windows at once, a series of cals to
  28.        wrefresh() will result in alternating calls to wnoutrefresh()
  29.        and doupdate(), causing several bursts of output to the
  30.        screen.  By first calling wnoutrefresh() for each window, it
  31.        is then possible to call doupdate() once.  This results in
  32.        only one burst of output, with probably fewer total characters
  33.        transmitted and certainly less CPU time used.
  34.  
  35.   PDCurses Description:
  36.        In addition to the above, if REGISTERWINDOWS is TRUE when the
  37.        library was compiled, any windows registered (true by default
  38.        with PDCurses and _cursvar.refreshall is TRUE, then all
  39.        registered windows will be called via wnoutrefresh() before
  40.        the actual screen update begins.
  41.  
  42.   X/Open Return Value:
  43.        The doupdate() function returns OK on success and ERR on error.
  44.  
  45.   X/Open Errors:
  46.        No errors are defined for this function.
  47.  
  48.   Portability:
  49.        PDCurses        int wnoutrefresh( WINDOW* w );
  50.        X/Open Dec '88  int wnoutrefresh( WINDOW* w );
  51.        BSD Curses      int wnoutrefresh( WINDOW* w );
  52.        SYS V Curses    int wnoutrefresh( WINDOW* w );
  53.  
  54. **man-end**********************************************************************/
  55.  
  56. int    wnoutrefresh(register WINDOW *win)
  57. {
  58. register chtype*       dstp;
  59. register chtype*       srcp;
  60. register int           first;  /* first changed char on line */
  61. register int           last;   /* last changed char on line  */
  62.        int             begy;   /* window's place on screen   */
  63.        int             begx;
  64.        WINDOW*         s;
  65.        int             i;
  66.        int             j;
  67.        int             y;
  68.        int             x;
  69.        int             len;
  70.        chtype          attrs;
  71.  
  72.        if (win == (WINDOW *)NULL)
  73.                return( ERR );
  74.  
  75.        y = win->_cury;
  76.        x = win->_curx;
  77.        attrs = win->_attrs;
  78.        if (win->_title != NULL)
  79.                len = strlen(win->_title);
  80.        /*
  81.         * There may be a better place to implement window titles, but this
  82.         * seems to be the best place. -- Frotz
  83.         */
  84.        if ((len > 0) && (win->_title != NULL) && !(win->_flags & _SUBWIN))
  85.        {
  86.                wattrset(win, win->_title_attr);
  87.                mvwprintw(win, 0, (win->_title_ofs), "%s", (long) win->_title);
  88.                wmove(win, y, x);       /* restore cursor postion */
  89.                wattrset(win, attrs);   /* restore attributes     */
  90.        }
  91.  
  92.        if (win->_flags & _PAD)
  93.                return( ERR );
  94.  
  95.        s = tmpwin;
  96.        begy = win->_begy;
  97.        begx = win->_begx;
  98.  
  99.        for (i = 0, j = begy; i < win->_maxy; i++, j++)
  100.        {
  101.                if (win->_firstch[i] != _NO_CHANGE)
  102.                {
  103.                        first = win->_firstch[i];
  104.                        last = win->_lastch[i];
  105.  
  106. #if    defined(DOS) || defined(OS2)
  107. #  if  SMALL || MEDIUM
  108.                        srcp = &(win->_y[i][first]);
  109.                        dstp = &(s->_y[j][begx + first]);
  110.                        movedata( FP_SEG(srcp), FP_OFF(srcp),
  111.                                  FP_SEG(dstp), FP_OFF(dstp),
  112.                                  (last - first + 1) * sizeof(chtype));
  113. #  else
  114.                        memcpy(&(s->_y[j][begx + first]),
  115.                               &(win->_y[i][first]),
  116.                               (last - first + 1) * sizeof(chtype));
  117. #  endif
  118. #endif
  119.                        first += begx;  /* s's min/max change positions */
  120.                        last += begx;
  121.  
  122.                        if (s->_firstch[j] != _NO_CHANGE)
  123.                                s->_firstch[j] = min(s->_firstch[j], first);
  124.                        else
  125.                                s->_firstch[j] = first;
  126.  
  127.                        s->_lastch[j] = max(s->_lastch[j], last);
  128.  
  129.                        win->_firstch[i] = _NO_CHANGE;  /* updated now */
  130.                }
  131.                win->_lastch[i] = _NO_CHANGE;   /* updated now */
  132.        }
  133.  
  134.        if (win->_clear)
  135.        {
  136.                win->_clear = FALSE;
  137.                s->_clear = TRUE;
  138.        }
  139.  
  140.        if (!win->_leave)
  141.        {
  142.                s->_cury = win->_cury + begy;
  143.                s->_curx = win->_curx + begx;
  144.        }
  145.        return( OK );
  146. }
  147.